<template>
  <div class="MonitorInfo">
    <el-row type="flex" justify="center">
      <el-col :span="15">
        <el-table
            :data="tableData"
            style="width: 100%"
            v-loading="loading"
        >
          <el-table-column
              prop="name"
              label="用户"
              width="180">
          </el-table-column>
          <el-table-column
              prop="title"
              label="题目"
              width="180">
          </el-table-column>
          <el-table-column
              prop="date"
              label="答题时间"
              width="180">
          </el-table-column>
          <el-table-column
              prop="flag"
              label="答案记录">
          </el-table-column>
          <el-table-column
              prop="answer"
              label="正确性">
          </el-table-column>
          <el-table-column align="right">
            <template slot="header">
              <el-select size="small" v-model="value" placeholder="请选择用户">
                <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: "MonitorInfo",
  mounted() {
    function formatDate(date) {
      let d = new Date(date),
          month = '' + (d.getMonth() + 1),
          day = '' + d.getDate(),
          year = d.getFullYear(),
          hour = d.getHours(),
          minute = d.getMinutes();

      if (month.length < 2) month = '0' + month;
      if (day.length < 2) day = '0' + day;
      let yearTime = [year, month, day].join('-')
      let dayTime = [hour, minute].join(':')
      return yearTime + " " + dayTime;
    }
    this.loading = true
    this.$axios2.post('/autoInfo').then((res) => {
      let data = res.data.msg
      for (let i = 0; i < data.length; i++) {
        let answer = ''
        if (data[i].Answer === true) {
          answer = '正确'
        } else {
          answer = '错误'
        }
        let list = {}
        list.date = formatDate(data[i].CreatedAt)
        list.title = data[i].title
        list.name = data[i].UserName
        list.flag = data[i].flag
        list.answer = answer
        this.tableData.push(list)
      }
      this.loading = false
    })
  },
  data() {
    return {
      tableData: [],
      options: [{
        value: '用户1',
        label: '用户1'
      }],
      value: '',
      loading:false,
    }
  }
}
</script>

<style scoped>

</style>